﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace XDA_ROM_Hub
{
    public partial class StockRomInstall : Form
    {
        public StockRomInstall()
        {
            InitializeComponent();
            UserClosing = false;
            //this.buttonExit.Click += new EventHandler(buttonExit_Click);
            this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
        }
        public bool UserClosing { get; set; }

        void buttonExit_Click(object sender, EventArgs e)
        {
            UserClosing = true;
            cencelbtn();
        }

        void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            switch (e.CloseReason)
            {
                case CloseReason.ApplicationExitCall:
                    break;
                case CloseReason.FormOwnerClosing:
                    break;
                case CloseReason.MdiFormClosing:
                    break;
                case CloseReason.None:
                    break;
                case CloseReason.TaskManagerClosing:
                    break;
                case CloseReason.UserClosing:
                    if (UserClosing)
                    {
                        cencelbtn();
                    }
                    else
                    {
                        cencelbtn();
                    }
                    break;
                case CloseReason.WindowsShutDown:
                    break;
                default:
                    break;
            }
        }

        public void cencelbtn()
        {
        	this.Hide();

        }
        private void button1_Click(object sender, EventArgs e)
        {
            bool EnableGuide = Properties.Settings.Default.EnableGuide;
            if (EnableGuide == true)
            {
                MessageBox.Show("Don't freek out from all of the buttons, just do what you've been told to do ;)", "Guide", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            System.Diagnostics.ProcessStartInfo p = new System.Diagnostics.ProcessStartInfo(@"C:\Flashtool\FlashTool.exe");
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = p;

            proc.Start();
            proc.WaitForExit();

            MessageBox.Show("Finished!","Success!", MessageBoxButtons.OK,MessageBoxIcon.Information);
            
            this.Hide();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.Diagnostics.ProcessStartInfo p = new System.Diagnostics.ProcessStartInfo(Application.StartupPath + @"flashtool.exe");
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = p;

            proc.Start();
            proc.WaitForExit();

            MessageBox.Show("Installed");
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        
    }
}
